define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sales/report/checkoutgoods/index' + location.search,
                    // add_url: 'sales/checkoutgoods/add',
                    // edit_url: 'sales/checkoutgoods/edit',
                    // del_url: 'sales/checkoutgoods/del',
                    multi_url: 'sales/checkoutgoods/multi',
                    table: 'sales_checkout_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false,formatter:function(value,row){
                            return '<div class="cid" style="text-align: center;" data-ccc="'+row.controller+'" data-objid="'+row.sales_checkout_id+'" data-id="'+row.id+'">'+value+'</div>'
                        }},
                        {field: 'number', title: __('单据编号'),operate:false},
                        {field: 'createtime', title: __('单据日期'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'type', title: __('单据类型'),operate:false},
                        // {field: 'type', title: __('单据类型'),searchList: $.getJSON(Config.this_url+"/sales/report/checkoutgoods/getgroup?state=2")},
                        {field: 'ccompany', title: __('结算单位'),operate:false},
                        // {field: 'customer.nickname', title: __('职员名称'),operate:false},
                        {field: 'name', title: __('仓库名称'),operate:false},
                        {field: 'gnumber', title: __('商品编号'),operate:false},
                        {field: 'title', title: __('商品名称'),operate:false},
                        {field: 'specs', title: __('商品规格'),operate:false},
                        // {field: 'goods.unit', title: __('单位'),operate:false},
                        {field: 'goods_num', title: __('销售数量'), operate:false},
                        {field: 'sale_price', title: __('单价'), operate:false},
                        {field: 'sale_money', title: __('销售金额'),operate:false},
                        {field: 'sfhj', title: __('价税合计'),operate:false},
                        {field: 'tax', title: __('税率'),operate:false},
                        {field: 'taxmoney', title: __('税额'),operate:false},
                        {field: 'costPrice', title: __('成本单价'),operate:false},
                        {field: 'costmoney', title: __('成本金额'),operate:false},
                        {field: 'unit_allfare', title: __('采购运费'),operate:false},
                        // {field: 'cost', title: __('格外费用'),operate:false},
                        // {field: 'cost_type', title: __('费用类型'),operate:false},
                        // {field: 'status', title: __('费用分摊金额')},
                        {field: 'maoli', title: __('毛利'),operate:false},
                        {field: 'maolil', title: __('毛利率'),operate:false},
                        {field: 'operator', title: __('制单人'),operate:false},
                        {field: 'source_admin', title: __('订单来源'),operate:false},
                        {field: 'company', title: __('部门'),searchList: $.getJSON(Config.this_url+"/sales/report/checkoutgoods/getgroup?state=1")},
                        {field: 'explain', title: __('摘要'),operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            $('table').on('dblclick','td',function(){
                // var cid = $(this).parents('tr').find('.cid').html()
                var objid = $(this).parents('tr').find('.cid').data('objid')
                var ccc = $(this).parents('tr').find('.cid').data('ccc')
                // console.log(objid)
                // return
                // console.log(out_id)
                var url = Config.this_url+'/'+ccc+'/detail?ids='+objid
                layer.open({
                    type: 2, // 1-在content中写html代码， 2-在content中写src路径
                    area: ['80%', '90%'],
                    title: "单据详情",
                    content: url,
                    // content: Config.this_url+'/purchase/requisition',
                })
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});